package com.beimi.game.cmd;

import com.beimi.game.BaseGame;
import com.beimi.game.MJService;
import com.beimi.game.module.GamePlayerModule;
import com.beimi.game.module.GameTurnModule;
import com.beimi.game.player.GamePlayer;
import com.beimi.game.player.PlayerCardModule;
import com.beimi.net.AbstractGameCmd;
import com.next.core.util.GenericAnnotation;

@GenericAnnotation(type = "peng")
public class CmdPeng extends AbstractGameCmd {

	@Override
	public void execute(MJService service, GamePlayer player, String data) {
		BaseGame game = service.getGame();
		// 如果是他出的牌，则忽略
		if (game.checkTurn(player)) {
			LOG.warn("it's your turn.");
			return;
		}

		PlayerCardModule cardModule = player.getCardModule();
		// 如果没有碰的机会，则不能再碰
		if (!cardModule.isCanPeng()) {
			LOG.warn("seatData.peng == false");
			return;
		}

		// 和的了，就不要再来了
		if (cardModule.isHued()) {
			LOG.warn("you have already hued. no kidding plz.");
			return;
		}

		if (game.getModule(GamePlayerModule.class).hasCanHuPlayer(player)) {
			return;
		}

		game.getModule(GamePlayerModule.class).clearOperations();

		if (cardModule.getCountMap().get(game.getChuPai()) < 2) {
			LOG.warn("you pai count is not enough.");
			return;
		}

		cardModule.remove(game.getChuPai());
		cardModule.remove(game.getChuPai());
		cardModule.getPengs().add(game.getChuPai());
		game.setChuPai(-1);

		game.getModule(GamePlayerModule.class).broacastInRoom("peng_notify_push", "", player);
		//
		// recordGameAction(game,seatData.seatIndex,ACTION_PENG,pai);
		//
		// //广播通知其它玩家
		// userMgr.broacastInRoom('peng_notify_push',{userid:seatData.userId,pai:pai},seatData.userId,true);
		//
		// //碰的玩家打牌
		game.getModule(GameTurnModule.class).incrTurn();
		// moveToNextUser(game,seatData.seatIndex);
		//
		// //广播通知玩家出牌方
		// seatData.canChuPai = true;
		// userMgr.broacastInRoom('game_chupai_push',seatData.userId,seatData.userId,true);
	};
}
